<template>
    <div>
        <el-row>
            <el-col :span="4">
                <el-input placeholder="请输入账号" v-model="input" clearable>
                </el-input>
            </el-col>
            <el-button style="margin-right: 900px;" type="primary" @click="selectadmin">
                搜索
            </el-button>
        </el-row>
        <el-row style="margin-top: 20px;">
            <el-col>
                <template>
                    <el-table :data="page.list" style="width: 100%">
                        <el-table-column label="照片" width="80">
                            <template slot-scope="scope">
                                <img :src="scope.row.certifiedInfoImg" style="max-width: 80px; max-height: 80px;" />
                            </template>
                        </el-table-column>
                        <el-table-column prop="certifiedInfoName" label="物业名字" width="140">
                        </el-table-column>
                        <el-table-column prop="certifiedInfoTel" label="物业电话" width="140">
                        </el-table-column>
                        <el-table-column prop="certifiedInfoAddTime" label="创建时间" width="180">
                        </el-table-column>
                        <el-table-column prop="certifiedInfoAddPerson" label="创建人" width="140">
                        </el-table-column>
                        <el-table-column prop="certifiedInfoAddress" label="详细地址" width="140">
                        </el-table-column>
                        <el-table-column prop="certifiedInfoLatitude" label="经度" width="80">
                        </el-table-column>
                        <el-table-column prop="certifiedInfoLongitude" label="纬度" width="80">
                        </el-table-column>
                        <el-table-column prop="address" label="操作">
                            <div style="display: flex;" slot-scope="scope">
                                <el-button type="primary" @click="ok(scope.row)">通过</el-button>
                                <el-button type="danger" style="margin-left: 20px;" @click="notok(scope.row)">拒绝</el-button>
                            </div>
                        </el-table-column>
                    </el-table>
                </template>
            </el-col>
        </el-row>
        <!-- 分页按钮 -->
        <el-row>
            <el-col :span="24">
                <el-pagination background layout="total, prev, pager, next" :page-size="page.size" :total="page.total"
                    @current-change="changePageNum">
                </el-pagination>
            </el-col>
        </el-row>

        <!-- 通过消息提示框 -->
        <el-dialog title="请通知其物业申请通过" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
            <span>超级管理员账号:</span>
            {{ CertifiedAccountDto.certifiedAccountAccount }}
            <span>超级管理员密码:</span>
            {{ CertifiedAccountDto.certifiedAccountPass }}
            <span>联系电话:</span>
            {{ phone }}
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
            </span>
        </el-dialog>

        <!-- 驳回消息提示框 -->
        <el-dialog title="请通知其物业申请失败" :visible.sync="dialogVisible2" width="30%" :before-close="handleClose">
            <span>联系电话:</span>
            {{ phone }}
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible2 = false">取 消</el-button>
                <el-button type="primary" @click="dialogVisible2 = false">确 定</el-button>
            </span>
        </el-dialog>

    </div>
</template>

<script>
import router from '../router';

export default {
    name: "PassAllAppLication",
    data() {
        return {
            phone: "",
            dialogVisible: false,
            dialogVisible2: false,
            input: "",
            platformAccounts: "",
            page: {},
            CertifiedAccountDto: {},
            logoUrl: "../../static/images/system/woniu.png",
            pageNum: "",
            pageSize: "",
        };
    },
    methods: {
        handleClose(done) {
            this.$confirm('确认关闭？')
                .then(_ => {
                    done();
                })
                .catch(_ => { });
        },
        notok(obj) {
            this.phone=obj.certifiedInfoTel
            let certifiedInfoIds = obj.certifiedInfoId
            this.$http.get("/certified/applicationForm/refuseApplication", {
                params: {
                    id: certifiedInfoIds
                }
            }).then(resp => {
                console.log(resp)
                alert(resp.data.message)
                if(resp.data.code==200){
                    this.dialogVisible2=true
                    this.passAllApplication()
                }
            })
        },
        ok(obj) {
            this.phone = obj.certifiedInfoTel
            let certifiedInfoIds = obj.certifiedInfoId;
            this.$http.get("/certified/applicationForm/passApplication", {
                params: {
                    id: certifiedInfoIds
                }
            }).then(resp => {
                alert(resp.data.message);
                this.CertifiedAccountDto = resp.data.data
                this.dialogVisible = true
                this.passAllApplication();
            });
        },
        selectadmin() {
            if (this.input) {
                this.$http.get("/certified/applicationForm/LoadcertifiedBycertifiedInfoName", {
                    params: {
                        certifiedInfoName: this.input
                    }
                }).then(resp => {
                    console.log(resp);
                    this.page.list = [resp.data.data]; // 将返回的单个对象转换成数组赋值给page.list
                    this.page.total = 1; // 更新total属性
                    this.page.size = 1; // 更新size属性（假设每页显示10条数据，根据实际情况修改）
                });
            } else {
                this.passAllApplication();
            }
        },
        changePageNum(pageNum) {
            this.pageNum = pageNum;
            this.passAllApplication();
        },
        passAllApplication() {
            if (!this.pageNum) {
                this.pageNum = 1;
            }
            if (!this.pageSize) {
                this.pageSize = 6; // 默认每页显示10条数据，根据实际情况修改
            }
            this.$http.get("/certified/applicationForm/passAllApplication", {
                params: {
                    pageNum: this.pageNum,
                    pageSize: this.pageSize
                }
            }).then(resp => {
                console.log(resp)
                this.page = resp.data.data;
            });
        }
    },
    created() {
        this.passAllApplication()
    },
    components: { router }
}
</script>

<style scoped>
html,
body {
    height: 100%;
}
</style>